package com.view.viewer;

import com.utils.JdbcUtils;
import com.view.coach.CoachMain;
import com.view.footballer.FootballerMain;
import com.view.footballteam.FootballTeamMain;
import com.view.judge.JudgeMain;
import com.view.match_result_end.MatchResultEndMain;
import com.view.text.TextMain;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.URI;


public class MainView {
    private JButton cm=new JButton("教练信息");
    private JButton fm=new JButton("球员信息");
    private JButton ft=new JButton("球队信息");
    private JButton jd=new JButton("裁判信息");
    private JButton mrem=new JButton("最终比赛信息");
    private JButton mshow=new JButton("球队详情");
    private JButton text=new JButton("关于");
    JFrame jf;
    public MainView(){
        jf=new JFrame("比赛信息");
        jf.setSize(450,150);
        jf.setLayout(null);

        cm.setSize(90,30);
        fm.setSize(90,30);
        ft.setSize(90,30);
        jd.setSize(90,30);
        mrem.setSize(130,30);
        mshow.setSize(130,30);
        text.setSize(90,30);

        cm.setLocation(20,20);
        fm.setLocation(120,20);
        ft.setLocation(220,20);
        jd.setLocation(320,20);
        mrem.setLocation(20,60);
        mshow.setLocation(170,60);
        text.setLocation(320,60);

        /**
         * 加入事件监听
         */
        cm.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(e.getSource().equals(cm)){
                    new CoachMain();
                }
            }
        });
        fm.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(e.getSource().equals(fm)){
                    new FootballerMain();
                }
            }
        });
        ft.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(e.getSource().equals(ft)){
                    new FootballTeamMain();
                }
            }
        });
        jd.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(e.getSource().equals(jd)){
                    new JudgeMain();
                }
            }
        });
        mrem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(e.getSource().equals(mrem)){
                    new MatchResultEndMain();
                }
            }
        });
        String a=JdbcUtils.getShowUrl();
        System.out.println(a);
        java.awt.Desktop dp = java.awt.Desktop.getDesktop();

        mshow.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(e.getSource().equals(mshow)){
                    try {
                        dp.browse(URI.create(a));// 获取系统默认浏览器打开链接
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }
            }
        });
        jf.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                super.windowClosed(e);
                System.exit(0);
            }
        });
        text.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(e.getSource().equals(text)){
                    new TextMain();
                }
            }
        });

        jf.add(cm);
        jf.add(fm);
        jf.add(ft);
        jf.add(jd);
        jf.add(mrem);
        jf.add(mshow);
        jf.add(text);

        jf.setLocation(400,300);
        jf.setVisible(true);
    }
}
